<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="告警类型" prop="alertType">
        <el-select v-model="form.alertType" filterable clearable>
          <el-option
            v-for="item in dict.type.sys_alarm_type"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="告警级别" prop="alertLevel">
        <el-select v-model="form.alertLevel" filterable clearable>
          <el-option
            v-for="item in dict.type.sys_alarm_level"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否已处理" prop="handled">
        <el-select v-model="form.handled" filterable clearable>
          <el-option
            v-for="item in dict.type.sys_yes_no"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="处理人" prop="handler">
        <el-input v-model="form.handler" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="时间范围" prop="time">
        <el-date-picker v-model="form.time" type="daterange"
                        start-placeholder="开始日期" end-placeholder="结束日期"  value-format="yyyy-MM-dd" clearable></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="alertDesc" label="告警类型" align="center">
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.sys_alarm_type" :value="scope.row.alertType"/>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column prop="alertLevel;" label="告警级别" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_alarm_level" :value="scope.row.alertLevel"/>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="告警标题" align="center"/>
      <el-table-column prop="businessNo" label="业务单号" align="center"/>
      <el-table-column prop="content" label="告警内容" align="center"/>
      <el-table-column prop="createTime" label="告警时间" align="center"/>
      <el-table-column prop="handler" label="处理人" align="center" width="100"/>
      <el-table-column prop="handleTime" label="处理时间" align="center"/>
      <el-table-column prop="handled" label="是否已处理" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.handled"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-hasPermi="['ims:alarmList:handle']"
            :disabled="scope.row.handled==0"
            @click="handleRow(scope.row)"
          >处理
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

import {handelAlarm, listAlarm} from "../../../api/alarmMng";
import {deleteProducePlan} from "../../../api/produceMng";

export default {
  dicts: ['sys_alarm_level', 'sys_yes_no','sys_alarm_type'],
  data() {
    return {
      tabIndex:'0',
      loading: false,
      list: [],
      form: {
        alertType: "",
        alertLevel: "",
        handled: "",
        handler: "",
        time:[],
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    handleRow(row){
      this.$modal.confirm('是否确定已处理').then(res => {
        this.loading=true
        handelAlarm(row.id).then(res => {
          this.handleQuery()
          this.$message.success('处理成功')
        }).finally(e => {
          this.loading = false
        })
      })
    },
    getList() {
      if(this.form.time&&this.form.time.length){
        this.form.startTime=this.form.time[0]
        this.form.endTime=this.form.time[1]
      }else{
        this.form.startTime=''
        this.form.endTime=''
      }
      this.loading=true
      listAlarm(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    }
  }
}
</script>
